package com.itheima.map;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Random;

/**
 * @author zhangbaiyan
 * @date 2024-09-12 12:43
 * @description:
 * @version:
 */
public class Test2 {
    public static void main(String[] args) {
        String[] arr = new String[]{"a", "b", "c", "d"};

        ArrayList<String> list = new ArrayList<>();
        Random r = new Random();
        for (int i = 0; i < 80; i++) {
            int index = r.nextInt(arr.length);
            list.add(arr[index]);
        }
//        System.out.println(list);

        HashMap<String, Integer> map = new HashMap<>();
        for (String s : list) {
            if (map.containsKey(s)) {
                map.put(s, map.get(s) + 1);
            } else {
                map.put(s, 1);
            }
        }


        System.out.println("===========================");

        //3.求最大值
        int max = map.values().stream().mapToInt(value -> value).filter(value -> value >= 0).max().orElse(0);

        map.forEach((k, v) -> {
            if (v == max) {
                System.out.println("投票最多的是"+k+",票数是:"+v);
            }

        });


    }
}


